import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'

// 经销商分页查询与详情

/**
 * 分页查询
 * @param {object} data 参数
 */
export function getDealerList({ page, rows, sort, order, filtersRaw, sortersRaw, paramsRaw }: any) {
  const params = {
    page,
    rows,
    sort: sort || '',
    order: order || 'DESC',
    pageFlag: true,
    onlyCountFlag: false,
    filtersRaw: JSON.stringify(filtersRaw),
    sortersRaw: JSON.stringify(sortersRaw),
    paramsRaw: JSON.stringify(paramsRaw)
  }
  const data = json2FormData(params)
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/ctmMdmCustomer/page`,
    data,
    headers: {
      'Permission-PerCode': 'dealercustomer',
      'Permission-App': 'CTM_APP'
    }
  })
}

/**
 * 详情
 * @param {string} code
 */
export function detail(code: string) {
  return request<IResponseData>({
    method: 'get',
    url: `/app/v1/ctmMdmCustomer/detail/${code}`
  })
}
